﻿//  Copyright (c) 2011 Ray Liang (http://www.dotnetage.com)
//  Licensed MIT: http://www.opensource.org/licenses/mit-license.php

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Security.Principal;
using System.Web.Profile;
using System.Web.Mvc;
//using DNA.Mvc;

namespace DNA.Mvc
{
    public static class UrlResolver
    {
        //public static HttpContext HttpContext
        //{
        //    get
        //    {
        //        return HttpContext.Current;
        //    }
        //}

        public static string ApplicationPath
        {
            get
            {
                return Resolve(new HttpContextWrapper(HttpContext.Current));
            }
        }

        public static string Resolve(HttpContextBase httpContext)
        {
            var request = httpContext.Request;
            string url = request.Url.Scheme + "://" + request.Url.Authority;
            if (!request.ApplicationPath.Equals("/"))
                url += request.ApplicationPath;
            return url;
        }

        public static string Resolve(Web web)
        {
            return Resolve(new HttpContextWrapper(HttpContext.Current), web);
        }

        public static string Resolve(HttpContextBase httpContext, Web web)
        {
            if (web.IsRoot)
                return Resolve(httpContext);
            else
                return Resolve(httpContext) + "/sites/" + web.Name;
        }

        public static string Content(Web web)
        {
            if (web != null)
            {
                return string.Format("/webshared/{0}/", web.Name);
            }
            return null;
        }

        public static string Resolve(WebPage page)
        {
            return Resolve(new HttpContextWrapper(HttpContext.Current), page);
        }

        public static string Resolve(HttpContextBase httpContext, WebPage page)
        {
            return Resolve(httpContext) + VirtualPathUtility.ToAbsolute(page.Path, httpContext.Request.ApplicationPath);
        }

        public static string Resolve(IPrincipal user)
        {
            return "";
        }

        public static string Resolve(IIdentity identity)
        {
            return "";
        }

        public static string Resolve(ProfileBase profile)
        {
            return "";
        }
    }

}
